package com.tjsinfo.tjsoa.worklog.action;

import java.text.SimpleDateFormat;

import javax.servlet.RequestDispatcher;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import com.tjsinfo.tjsoa.system.vo.User;
import com.tjsinfo.tjsoa.worklog.bo.IWorkLogMainBo;


public class UpdateWorkLogAction extends Action{
	private IWorkLogMainBo workLogMainBo;
		
	
public IWorkLogMainBo getWorkLogMainBo() {
	return workLogMainBo;
}


public void setWorkLogMainBo(IWorkLogMainBo workLogMainBo) {
	this.workLogMainBo = workLogMainBo;
}


	/* (non-Javadoc)
	 * @see org.apache.struts.action.Action#execute(org.apache.struts.action.ActionMapping, org.apache.struts.action.ActionForm, javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
	 */
	@Override
	public ActionForward execute(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse response)
			throws Exception {
		// TODO Auto-generated method stub
		try {
			String time = request.getParameter("time");
			SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
			HttpSession session = request.getSession();
			User user = (User) session.getAttribute("user");
			workLogMainBo.update(request.getParameter("id"), user.getUser_id(), simpleDateFormat.parse(time), request.getParameter("type"), request.getParameter("contest"), "",Integer.parseInt(request.getParameter("year")),Integer.parseInt(request.getParameter("number")),Integer.parseInt(request.getParameter("start")));
			if("list".equals(request.getParameter("type")))
			{
				RequestDispatcher   ds   =   request.getRequestDispatcher("workLoglistmode.do?id="+request.getParameter("id")+"&type="+request.getParameter("logtype")); 
				ds.forward(request,   response);
			}
			else if("D".equals(request.getParameter("type")))
			{
				request.setAttribute("linkurl", "tjsinfo/tjsoa/worklog/workLogDateModle.do");
				request.setAttribute("message", "worklog.message.update");
				return mapping.findForward("success");
				
			}
			else if("W".equals(request.getParameter("type")))
			{
				request.setAttribute("linkurl", "tjsinfo/tjsoa/worklog/workLogWeekModle.do");
				request.setAttribute("message", "worklog.message.update");
				return mapping.findForward("success");
			}
			else if("M".equals(request.getParameter("type")))
			{
				request.setAttribute("linkurl", "tjsinfo/tjsoa/worklog/workLogMonthModle.do");
				request.setAttribute("message", "worklog.message.update");
				return mapping.findForward("success");
			}
			else if("Q".equals(request.getParameter("type")))
			{
				request.setAttribute("linkurl", "tjsinfo/tjsoa/worklog/workLogJiDuModle.do");
				request.setAttribute("message", "worklog.message.update");
				return mapping.findForward("success");
				
			}
			else if("H".equals(request.getParameter("type")))
			{
				request.setAttribute("linkurl", "tjsinfo/tjsoa/worklog/workLogHalfYearModle.do");
				request.setAttribute("message", "worklog.message.update");
				return mapping.findForward("success");
			}
			else if("Y".equals(request.getParameter("type")))
			{
				request.setAttribute("linkurl", "tjsinfo/tjsoa/worklog/workLogYearModle.do");
				request.setAttribute("message", "worklog.message.update");
				return mapping.findForward("success");
			}
			else if("list".equals(request.getParameter("type")))
			{
				
				request.setAttribute("linkurl", "tjsinfo/tjsoa/worklog/workLoglistmode.do");
				request.setAttribute("message", "worklog.message.update");
				return mapping.findForward("success");
			}
			return mapping.findForward("okY");
		} catch (RuntimeException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			return mapping.findForward("error");
		}
	
	}
}
